package network;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class TcpDictionaryServer extends TcpEchoServer{

    private Map<String,String> hashMap = new HashMap<>();
    public TcpDictionaryServer(int port) throws IOException {
        super(port);
        hashMap.put("hello","你好");
        hashMap.put("abandon","放弃");
        hashMap.put("animal","动物");
        hashMap.put("cat","小猫");
        hashMap.put("dog","小狗");
        //........

    }

    //这个时候会发生动态绑定，调用子类自己拓展的功能
    @Override
    public String process(String request) {
        return hashMap.getOrDefault(request,"没有这个单词");
    }

    public static void main(String[] args) throws IOException {
        TcpDictionaryServer dictionaryServer = new TcpDictionaryServer(9090);
        dictionaryServer.start();
    }
}
